package com.swanclouds.redfish.systems;

import com.google.common.base.Preconditions;
import com.swanclouds.api.systems.VLANService;
import com.swanclouds.core.transport.ClientConstants;
import com.swanclouds.model.common.redfish.CollectionResource;
import com.swanclouds.model.systems.EthernetInterfaceConfigure;
import com.swanclouds.model.task.Task;
import com.swanclouds.redfish.common.redfish.CollectionResourceModel;
import com.swanclouds.redfish.internal.BaseSystemService;
import com.swanclouds.redfish.systems.domain.VLAN;
import com.swanclouds.redfish.task.domain.TaskModel;

/**
 * @author 张立强
 * @version jdk1.8.0
 */
public class VLANServiceImpl extends BaseSystemService implements VLANService {
    /**
     * 查询VLAN集合资源信息
     * @param ethernetInterfaceId 以太网ID
     * @return CollectionResource
     */
    @Override
    public CollectionResource get(String ethernetInterfaceId) {
        return get(CollectionResourceModel.class, uri(ClientConstants.SYSTEMS_ETHERNET_INTERFACES_ID_VLANS, getSystemId(), ethernetInterfaceId)).execute();
    }

    /**
     * 查询 VLAN 资源信息
     *
     * @param vlanId              VLAN ID
     * @param ethernetinterfaceId 以太网ID
     * @return VLAN 资源
     */
    @Override
    public VLAN getVLAN(String vlanId, String ethernetinterfaceId) {
        Preconditions.checkNotNull(ethernetinterfaceId, "EthernetInterface Id is null");
        Preconditions.checkNotNull(vlanId, "VLAN Id is null");
        return get(VLAN.class,uri(ClientConstants.SYSTEMS_ETHERNET_INTERFACES_ID_VLANS_ID, getSystemId(), ethernetinterfaceId, vlanId)).execute();
    }

    /**
     * 配置VLAN
     * 仅支持Atlas系列产品，且需配合iBMA使用，iBMA版本号需大于或等于1.50.831。
     * X86系统是EulerOS且内核版本是3.10.0-327或3.10.0-514
     *
     * @param configure           VLAN Confiure
     * @param vlanId              VLAN ID
     * @param ethernetInterfaceId 以太网ID
     * @return Task
     */
    @Override
    public Task configure(EthernetInterfaceConfigure configure, String vlanId, String ethernetInterfaceId) {
        return post(TaskModel.class, uri(ClientConstants.SYSTEMS_ETHERNET_INTERFACES_ID_VLANS_ID_CONFIGURE, getSystemId(), ethernetInterfaceId, vlanId)).entity(configure).execute();
    }
}
